﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Text;

namespace EBA.WindowsServices
{
    /// <summary>
    /// 默认服务输出实现。
    /// </summary>
    [Serializable]
    public class RemotingWindowsServiceOutput : MarshalByRefObject, IWindowsServiceOutput
    {

        public void Write(OutputLevel level, string format, params object[] args)
        {
            this.OnContentOutputing(level, string.Format(format, args));
        }

        public void WriteLine(OutputLevel level, string format, params object[] args)
        {
            this.OnContentOutputing(level, string.Format(format, args) + Environment.NewLine);
        }

        public override object InitializeLifetimeService()
        {
            return null;
        }


        void OnContentOutputing(OutputLevel level, string content)
        {
            if (this.ContentOutputing != null)
            {
                this.ContentOutputing(this, new OutputEventArgs { Level = level, Content = content });
            }
        }

        public event EventHandler<OutputEventArgs> ContentOutputing;


    }
}
